package com.zm.common.core.util;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;

/**
 * CryptographyHelper
 * @author DENG.ZHUO.HUI
 * @email 13751827792@163.com
 * @date 2017年2月10日
 * @version 1.0
 */
public class CryptographyHelper {

	private static SecureRandomNumberGenerator generator = new SecureRandomNumberGenerator();
	/** 加密迭代次数 */
	private static final int HASH_ITERATIONS = 5;
	/** 加密算法名称 md5、 sha-1、sha-256、sha-384、sha-512 */
	private static final String ALGORITHM_NAME = "md5";
	
	public static String getRandomSalt(){
		return generator.nextBytes().toHex();
	}
	
	public static String encrypt(String source,String salt){
		return new SimpleHash(ALGORITHM_NAME, source, salt, HASH_ITERATIONS).toHex();
	}
}
